package br.sales.entity;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;

public class UserEntity implements Serializable{


	public static final int ADMIN = 0;
	public static final int COMMON = 1; 
	private long id;
	private String login;
	private String email;
	private String pass;
	private SystemLanguage language;
	private int type;
	private String picture;
	private boolean active = false;
	private List<MediaSocialEntity> mediaSocials = new ArrayList<MediaSocialEntity>();
	
	public UserEntity() {
	}
	
	public UserEntity(String login) {
		this.login = login;
	}

	
	public UserEntity(String login, String pass) {
		this.login = login;
		this.pass = pass;
	}

	public String getLogin() {
		return login;
	}
	
	public void setLogin(String login) {
		this.login = login;
	}
	public String getEmail() {
		return email;
	}
	
	public void setEmail(String email) {
		this.email = email;
	}
	
	public String getPass() {
		return pass;
	}
	
	public void setPass(String pass) {
		this.pass = pass;
	}
	
	public SystemLanguage getLanguage() {
		return language;
	}
	
	public void setLanguage(SystemLanguage language) {
		this.language = language;
	}
	
	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}
	
	public String getPicture() {
		return picture;
	}

	public void setPicture(String picture) {
		this.picture = picture;
	}
	
	public List<MediaSocialEntity> getMediaSocials() {
		return mediaSocials;
	}

	public void setMediaSocials(List<MediaSocialEntity> mediaSocials) {
		this.mediaSocials = mediaSocials;
	}
	
	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (id ^ (id >>> 32));
		result = prime * result + ((login == null) ? 0 : login.hashCode());
		result = prime * result + ((pass == null) ? 0 : pass.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UserEntity other = (UserEntity) obj;
		if (id != other.id)
			return false;
		if (login == null) {
			if (other.login != null)
				return false;
		} else if (!login.equals(other.login))
			return false;
		if (pass == null) {
			if (other.pass != null)
				return false;
		} else if (!pass.equals(other.pass))
			return false;
		return true;
	}
	
	
	public void copyFields(Object from) throws Exception {
		Class clazz = this.getClass();
		
		Field[] fields = clazz.getDeclaredFields();
		
		for (Field f: fields){
			Object object = f.get(from);
			if (object !=null && !Modifier.isFinal(f.getModifiers())){
				f.set(this,object);
			}
		}
		
		
	}
	
}
